using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;

namespace Main
{
    public class Option
    {
#region "Constructors"
        public Option()
        {
        }
        public Option(string p_sPollOption)
        {
            PollOption = p_sPollOption;
        }
        public Option(string p_sPollOption, int p_iPollID)
        {
            PollID = p_iPollID;
            PollOption = p_sPollOption;
        }
        public Option(string p_sPollOption, int p_iPollID, int p_iOptionID)
        {
            PollID = p_iPollID;
            PollOption = p_sPollOption;
            OptionID = p_iOptionID;
        }
        
#endregion
        
#region "Properties"
        private int _PollID = 0;
        public int PollID
        {
            get
            { return _PollID; }
            set
            { _PollID = value; }
        }

        private int _OptionID = 0;
        public int OptionID
        {
            get
            { return _OptionID; }
            set
            { _OptionID = value; }
        }

        private string _PollOption = "";
        public string PollOption
        {
            get
            { return _PollOption; }
            set
            { _PollOption = value; }
        }

        private int _TotalVotes = 0;
        public int TotalVotes
        {
            get
            { return _TotalVotes; }
            set
            { _TotalVotes = value; }
        }
#endregion

#region "Custom Methods"
        public void Log(TextWriter stream)
        {
            stream.WriteLine("OptionID: " + OptionID);
            stream.WriteLine("PollID: " + PollID);
            stream.WriteLine("Poll Option: " + PollOption);
            stream.WriteLine("Total Votes: " + TotalVotes);
        }
#endregion
    }

    public class OptionCollection :
        CollectionBase
    {
        public void Add(Option p_Option)
        {
            
            InnerList.Add(p_Option);
        }

        public void Remove(int p_iIndex)
        {
            InnerList.RemoveAt(p_iIndex);
        }

        public Option this[int index]
        {
            get
            { return (Option)InnerList[index]; }
        }

        public void FillByPollId(int p_iPollId)
        {
            try
            {
                DataTable dt = DataAccess.GetOptionsByPollID(p_iPollId);

                foreach (DataRow row in dt.Rows)
                {
                    Option newOption = new Option();
                    newOption.PollID = (int)row[dt.Columns.IndexOf("PollId")];
                    newOption.OptionID = (int)row[dt.Columns.IndexOf("OptionID")];
                    newOption.PollOption = (string)row[dt.Columns.IndexOf("PollOption")];
                    newOption.TotalVotes = (int)row[dt.Columns.IndexOf("Votes")];

                    InnerList.Add(newOption);
                }
            }
            catch (Exception e)
            {
            }
        }
    }
}
